{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "1315ca9f",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-22T11:08:48.762429Z",
     "start_time": "2022-03-22T11:08:48.536553Z"
    }
   },
   "outputs": [],
   "source": [
    "import requests"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "d199875e",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-15T11:55:27.512428Z",
     "start_time": "2022-03-15T11:55:26.080171Z"
    }
   },
   "outputs": [],
   "source": [
    "# 1.url(目标餐厅）\n",
    "face_detect_url = 'https://api-cn.faceplusplus.com/facepp/v3/detect'\n",
    "\n",
    "# 2.准备api账户/通行证\n",
    "API_key =  'r651d0HgsEQqL55hCh1ZkOSmvz-HB8vF'\n",
    "API_secret = 'xSAcmge4iFneFOlloAm9k8lFP8W3iZP1'\n",
    "\n",
    "# 3.\n",
    "payload = {\n",
    "    'api_key':'r651d0HgsEQqL55hCh1ZkOSmvz-HB8vF',\n",
    "    'api_secret':'xSAcmge4iFneFOlloAm9k8lFP8W3iZP1',\n",
    "    'image_url':'https://tse1-mm.cn.bing.net/th/id/OIP-C.HPWFQ7UDQh93EKcDmiUQ_wHaIR?w=176&h=197&c=7&r=0&o=5&dpr=2&pid=1.7'\n",
    "}\n",
    "\n",
    "r = requests.post(base_url,params = payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "94257ab2",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-15T11:55:27.605980Z",
     "start_time": "2022-03-15T11:55:27.582673Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [400]>"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "8084e541",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-15T12:32:01.588677Z",
     "start_time": "2022-03-15T12:32:01.578593Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'time_used': 48,\n",
       " 'error_message': 'VOID_REQUEST',\n",
       " 'request_id': '1647347174,866ade5d-c46f-4ca1-8568-d15d372e0d1a'}"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "070ac060",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-15T12:08:14.515760Z",
     "start_time": "2022-03-15T12:08:13.936900Z"
    }
   },
   "outputs": [],
   "source": [
    "# 2. 人脸分析（请尝试调用analyze接口）\n",
    "face_detect_url = 'https://api-cn.faceplusplus.com/facepp/v3/face/analyze'\n",
    "\n",
    "API_key =  'r651d0HgsEQqL55hCh1ZkOSmvz-HB8vF'\n",
    "API_secret = 'xSAcmge4iFneFOlloAm9k8lFP8W3iZP1'\n",
    "\n",
    "payload = {\n",
    "    'api_key':'r651d0HgsEQqL55hCh1ZkOSmvz-HB8vF',\n",
    "    'api_secret':'xSAcmge4iFneFOlloAm9k8lFP8W3iZP1',\n",
    "    'face_tokens':'b8c4b876eaf5fc3682eaa1318b2bdca9',\n",
    "    'return_attributes':'gender,age,smiling,headpose,facequality,blur,eyestatus,emotion,beauty,mouthstatus,eyegaze,skinstatus'\n",
    "}\n",
    "\n",
    "r = requests.post(face_detect_url,params = payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "3a999afd",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-15T12:08:14.594114Z",
     "start_time": "2022-03-15T12:08:14.582152Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "3d91d174",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-15T12:08:15.168585Z",
     "start_time": "2022-03-15T12:08:15.153623Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'time_used': 191,\n",
       " 'request_id': '1647346093,53d2fb76-6e03-462f-9df5-5d8f1bed2a55',\n",
       " 'faces': [{'attributes': {'emotion': {'sadness': 0.039,\n",
       "     'neutral': 0.001,\n",
       "     'disgust': 0.191,\n",
       "     'anger': 0.001,\n",
       "     'surprise': 0.031,\n",
       "     'fear': 0.001,\n",
       "     'happiness': 99.736},\n",
       "    'beauty': {'female_score': 58.555, 'male_score': 58.212},\n",
       "    'gender': {'value': 'Male'},\n",
       "    'age': {'value': 53},\n",
       "    'mouthstatus': {'close': 0.0,\n",
       "     'surgical_mask_or_respirator': 0.0,\n",
       "     'open': 100.0,\n",
       "     'other_occlusion': 0.0},\n",
       "    'glass': {'value': 'None'},\n",
       "    'skinstatus': {'dark_circle': 1.554,\n",
       "     'stain': 9.17,\n",
       "     'acne': 1.527,\n",
       "     'health': 11.352},\n",
       "    'headpose': {'yaw_angle': 2.7483263,\n",
       "     'pitch_angle': 14.900063,\n",
       "     'roll_angle': 0.5866398},\n",
       "    'blur': {'blurness': {'threshold': 50.0, 'value': 0.376},\n",
       "     'motionblur': {'threshold': 50.0, 'value': 0.376},\n",
       "     'gaussianblur': {'threshold': 50.0, 'value': 0.376}},\n",
       "    'smile': {'threshold': 50.0, 'value': 100.0},\n",
       "    'eyestatus': {'left_eye_status': {'normal_glass_eye_open': 0.005,\n",
       "      'no_glass_eye_close': 0.0,\n",
       "      'occlusion': 0.0,\n",
       "      'no_glass_eye_open': 99.995,\n",
       "      'normal_glass_eye_close': 0.0,\n",
       "      'dark_glasses': 0.0},\n",
       "     'right_eye_status': {'normal_glass_eye_open': 0.003,\n",
       "      'no_glass_eye_close': 0.0,\n",
       "      'occlusion': 0.001,\n",
       "      'no_glass_eye_open': 99.996,\n",
       "      'normal_glass_eye_close': 0.0,\n",
       "      'dark_glasses': 0.0}},\n",
       "    'facequality': {'threshold': 70.1, 'value': 85.357},\n",
       "    'eyegaze': {'right_eye_gaze': {'position_x_coordinate': 0.494,\n",
       "      'vector_z_component': 0.935,\n",
       "      'vector_x_component': -0.068,\n",
       "      'vector_y_component': 0.348,\n",
       "      'position_y_coordinate': 0.438},\n",
       "     'left_eye_gaze': {'position_x_coordinate': 0.502,\n",
       "      'vector_z_component': 0.942,\n",
       "      'vector_x_component': 0.247,\n",
       "      'vector_y_component': 0.227,\n",
       "      'position_y_coordinate': 0.422}}},\n",
       "   'face_rectangle': {'width': 107, 'top': 108, 'left': 141, 'height': 107},\n",
       "   'face_token': 'b8c4b876eaf5fc3682eaa1318b2bdca9'}]}"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json..()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "00a66403",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-15T12:08:17.897590Z",
     "start_time": "2022-03-15T12:08:17.892638Z"
    }
   },
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "8bfff6e6",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-15T12:08:18.382961Z",
     "start_time": "2022-03-15T12:08:18.355033Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>face_token</th>\n",
       "      <td>b8c4b876eaf5fc3682eaa1318b2bdca9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.emotion.sadness</th>\n",
       "      <td>0.039</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.emotion.neutral</th>\n",
       "      <td>0.001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.emotion.disgust</th>\n",
       "      <td>0.191</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.emotion.anger</th>\n",
       "      <td>0.001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.emotion.surprise</th>\n",
       "      <td>0.031</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.emotion.fear</th>\n",
       "      <td>0.001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.emotion.happiness</th>\n",
       "      <td>99.736</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.beauty.female_score</th>\n",
       "      <td>58.555</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.beauty.male_score</th>\n",
       "      <td>58.212</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.gender.value</th>\n",
       "      <td>Male</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.age.value</th>\n",
       "      <td>53</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.mouthstatus.close</th>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.mouthstatus.surgical_mask_or_respirator</th>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.mouthstatus.open</th>\n",
       "      <td>100.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.mouthstatus.other_occlusion</th>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.glass.value</th>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.skinstatus.dark_circle</th>\n",
       "      <td>1.554</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.skinstatus.stain</th>\n",
       "      <td>9.17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.skinstatus.acne</th>\n",
       "      <td>1.527</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.skinstatus.health</th>\n",
       "      <td>11.352</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.headpose.yaw_angle</th>\n",
       "      <td>2.748326</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.headpose.pitch_angle</th>\n",
       "      <td>14.900063</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.headpose.roll_angle</th>\n",
       "      <td>0.58664</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.blur.blurness.threshold</th>\n",
       "      <td>50.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.blur.blurness.value</th>\n",
       "      <td>0.376</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.blur.motionblur.threshold</th>\n",
       "      <td>50.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.blur.motionblur.value</th>\n",
       "      <td>0.376</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.blur.gaussianblur.threshold</th>\n",
       "      <td>50.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.blur.gaussianblur.value</th>\n",
       "      <td>0.376</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.smile.threshold</th>\n",
       "      <td>50.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.smile.value</th>\n",
       "      <td>100.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.eyestatus.left_eye_status.normal_glass_eye_open</th>\n",
       "      <td>0.005</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.eyestatus.left_eye_status.no_glass_eye_close</th>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.eyestatus.left_eye_status.occlusion</th>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.eyestatus.left_eye_status.no_glass_eye_open</th>\n",
       "      <td>99.995</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.eyestatus.left_eye_status.normal_glass_eye_close</th>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.eyestatus.left_eye_status.dark_glasses</th>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.eyestatus.right_eye_status.normal_glass_eye_open</th>\n",
       "      <td>0.003</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.eyestatus.right_eye_status.no_glass_eye_close</th>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.eyestatus.right_eye_status.occlusion</th>\n",
       "      <td>0.001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.eyestatus.right_eye_status.no_glass_eye_open</th>\n",
       "      <td>99.996</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.eyestatus.right_eye_status.normal_glass_eye_close</th>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.eyestatus.right_eye_status.dark_glasses</th>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.facequality.threshold</th>\n",
       "      <td>70.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.facequality.value</th>\n",
       "      <td>85.357</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.eyegaze.right_eye_gaze.position_x_coordinate</th>\n",
       "      <td>0.494</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.eyegaze.right_eye_gaze.vector_z_component</th>\n",
       "      <td>0.935</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.eyegaze.right_eye_gaze.vector_x_component</th>\n",
       "      <td>-0.068</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.eyegaze.right_eye_gaze.vector_y_component</th>\n",
       "      <td>0.348</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.eyegaze.right_eye_gaze.position_y_coordinate</th>\n",
       "      <td>0.438</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.eyegaze.left_eye_gaze.position_x_coordinate</th>\n",
       "      <td>0.502</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.eyegaze.left_eye_gaze.vector_z_component</th>\n",
       "      <td>0.942</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.eyegaze.left_eye_gaze.vector_x_component</th>\n",
       "      <td>0.247</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.eyegaze.left_eye_gaze.vector_y_component</th>\n",
       "      <td>0.227</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>attributes.eyegaze.left_eye_gaze.position_y_coordinate</th>\n",
       "      <td>0.422</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>face_rectangle.width</th>\n",
       "      <td>107</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>face_rectangle.top</th>\n",
       "      <td>108</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>face_rectangle.left</th>\n",
       "      <td>141</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>face_rectangle.height</th>\n",
       "      <td>107</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                                                   0\n",
       "face_token                                          b8c4b876eaf5fc3682eaa1318b2bdca9\n",
       "attributes.emotion.sadness                                                     0.039\n",
       "attributes.emotion.neutral                                                     0.001\n",
       "attributes.emotion.disgust                                                     0.191\n",
       "attributes.emotion.anger                                                       0.001\n",
       "attributes.emotion.surprise                                                    0.031\n",
       "attributes.emotion.fear                                                        0.001\n",
       "attributes.emotion.happiness                                                  99.736\n",
       "attributes.beauty.female_score                                                58.555\n",
       "attributes.beauty.male_score                                                  58.212\n",
       "attributes.gender.value                                                         Male\n",
       "attributes.age.value                                                              53\n",
       "attributes.mouthstatus.close                                                     0.0\n",
       "attributes.mouthstatus.surgical_mask_or_respirator                               0.0\n",
       "attributes.mouthstatus.open                                                    100.0\n",
       "attributes.mouthstatus.other_occlusion                                           0.0\n",
       "attributes.glass.value                                                          None\n",
       "attributes.skinstatus.dark_circle                                              1.554\n",
       "attributes.skinstatus.stain                                                     9.17\n",
       "attributes.skinstatus.acne                                                     1.527\n",
       "attributes.skinstatus.health                                                  11.352\n",
       "attributes.headpose.yaw_angle                                               2.748326\n",
       "attributes.headpose.pitch_angle                                            14.900063\n",
       "attributes.headpose.roll_angle                                               0.58664\n",
       "attributes.blur.blurness.threshold                                              50.0\n",
       "attributes.blur.blurness.value                                                 0.376\n",
       "attributes.blur.motionblur.threshold                                            50.0\n",
       "attributes.blur.motionblur.value                                               0.376\n",
       "attributes.blur.gaussianblur.threshold                                          50.0\n",
       "attributes.blur.gaussianblur.value                                             0.376\n",
       "attributes.smile.threshold                                                      50.0\n",
       "attributes.smile.value                                                         100.0\n",
       "attributes.eyestatus.left_eye_status.normal_gla...                             0.005\n",
       "attributes.eyestatus.left_eye_status.no_glass_e...                               0.0\n",
       "attributes.eyestatus.left_eye_status.occlusion                                   0.0\n",
       "attributes.eyestatus.left_eye_status.no_glass_e...                            99.995\n",
       "attributes.eyestatus.left_eye_status.normal_gla...                               0.0\n",
       "attributes.eyestatus.left_eye_status.dark_glasses                                0.0\n",
       "attributes.eyestatus.right_eye_status.normal_gl...                             0.003\n",
       "attributes.eyestatus.right_eye_status.no_glass_...                               0.0\n",
       "attributes.eyestatus.right_eye_status.occlusion                                0.001\n",
       "attributes.eyestatus.right_eye_status.no_glass_...                            99.996\n",
       "attributes.eyestatus.right_eye_status.normal_gl...                               0.0\n",
       "attributes.eyestatus.right_eye_status.dark_glasses                               0.0\n",
       "attributes.facequality.threshold                                                70.1\n",
       "attributes.facequality.value                                                  85.357\n",
       "attributes.eyegaze.right_eye_gaze.position_x_co...                             0.494\n",
       "attributes.eyegaze.right_eye_gaze.vector_z_comp...                             0.935\n",
       "attributes.eyegaze.right_eye_gaze.vector_x_comp...                            -0.068\n",
       "attributes.eyegaze.right_eye_gaze.vector_y_comp...                             0.348\n",
       "attributes.eyegaze.right_eye_gaze.position_y_co...                             0.438\n",
       "attributes.eyegaze.left_eye_gaze.position_x_coo...                             0.502\n",
       "attributes.eyegaze.left_eye_gaze.vector_z_compo...                             0.942\n",
       "attributes.eyegaze.left_eye_gaze.vector_x_compo...                             0.247\n",
       "attributes.eyegaze.left_eye_gaze.vector_y_compo...                             0.227\n",
       "attributes.eyegaze.left_eye_gaze.position_y_coo...                             0.422\n",
       "face_rectangle.width                                                             107\n",
       "face_rectangle.top                                                               108\n",
       "face_rectangle.left                                                              141\n",
       "face_rectangle.height                                                            107"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.json_normalize(r.json()['faces']).T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "7cb3a593",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-15T12:23:32.533068Z",
     "start_time": "2022-03-15T12:23:32.519979Z"
    }
   },
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (<ipython-input-38-1981042dff79>, line 11)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-38-1981042dff79>\"\u001b[1;36m, line \u001b[1;32m11\u001b[0m\n\u001b[1;33m    r = requests.post(face_detect_url,params = payload)\u001b[0m\n\u001b[1;37m    ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "# 3.人脸比对\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "1e73caee",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-15T12:26:15.525228Z",
     "start_time": "2022-03-15T12:26:15.195810Z"
    }
   },
   "outputs": [],
   "source": [
    "face_detect_url = 'https://api-cn.faceplusplus.com/facepp/v3/detect'\n",
    "\n",
    "# 2.准备api账户/通行证\n",
    "API_key =  'r651d0HgsEQqL55hCh1ZkOSmvz-HB8vF'\n",
    "API_secret = 'xSAcmge4iFneFOlloAm9k8lFP8W3iZP1'\n",
    "\n",
    "# 3.\n",
    "payload = {\n",
    "    'api_key':'r651d0HgsEQqL55hCh1ZkOSmvz-HB8vF',\n",
    "    'api_secret':'xSAcmge4iFneFOlloAm9k8lFP8W3iZP1',\n",
    "    'image_url':'https://tse1-mm.cn.bing.net/th/id/R-C.f9cb89d10352fa8d55b852ee61319833?rik=lqFSnXntKdwTnw&riu=http%3a%2f%2fi2.hdslb.com%2fbfs%2farchive%2f55452a6f8dbb7e4de77d441c5fb67da8e0dc2da9.jpg&ehk=%2f%2b%2bd%2fAcUTbC3OJ9a8XDAdOrWvcZWbZpZR9XWzUtcxDs%3d&risl=&pid=ImgRaw&r=0'\n",
    "}\n",
    "\n",
    "r = requests.post(base_url,params = payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "0a620231",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-15T12:26:18.623180Z",
     "start_time": "2022-03-15T12:26:18.602234Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [400]>"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "c796fa85",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-15T12:26:24.514640Z",
     "start_time": "2022-03-15T12:26:24.506659Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'time_used': 48,\n",
       " 'error_message': 'VOID_REQUEST',\n",
       " 'request_id': '1647347174,866ade5d-c46f-4ca1-8568-d15d372e0d1a'}"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "6aa42e37",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-15T12:42:38.383269Z",
     "start_time": "2022-03-15T12:42:38.367190Z"
    }
   },
   "outputs": [],
   "source": [
    "Liu_face01 = ''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "5f7a2972",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-15T12:45:05.491356Z",
     "start_time": "2022-03-15T12:45:05.474399Z"
    }
   },
   "outputs": [],
   "source": [
    "API_key =  'r651d0HgsEQqL55hCh1ZkOSmvz-HB8vF'\n",
    "API_secret = 'xSAcmge4iFneFOlloAm9k8lFP8W3iZP1'\n",
    "image_url='https://tse1-mm.cn.bing.net/th/id/OIP-C.HPWFQ7UDQh93EKcDmiUQ_wHaIR?w=176&h=197&c=7&r=0&o=5&dpr=2&pid=1.7'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "a6d93325",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-15T12:47:33.383830Z",
     "start_time": "2022-03-15T12:47:33.367905Z"
    }
   },
   "outputs": [],
   "source": [
    "# 思考：能否将一些功能作函数封装\n",
    "def face_detect(API_key,API_secret,image_url,landmark=None,attributes=None):\n",
    "    \"\"\"face++ 人脸接口函数(图片链接)\"\"\"\n",
    "    url = 'https://api-cn.faceplusplus.com/facepp/v3/detect'\n",
    "    payload={\n",
    "        'api_key':API_key,\n",
    "        'api_secret':API_secret,\n",
    "        'image_url':image_url,\n",
    "        'return_lanmark':landmark,\n",
    "        'return_attributes':attributes\n",
    "        \n",
    "    }\n",
    "    r = requests.post(url,payload)\n",
    "    return r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "1e1d208c",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-15T12:48:13.319656Z",
     "start_time": "2022-03-15T12:48:12.862462Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'request_id': '1647348492,43de593f-dc14-4f67-903b-6b23b1ebf792',\n",
       " 'time_used': 213,\n",
       " 'faces': [{'face_token': '2c135d5fc4dbda8c5830bc9c7fb1c9ca',\n",
       "   'face_rectangle': {'top': 108, 'left': 141, 'width': 107, 'height': 107}}],\n",
       " 'image_id': 'JoYdaZ0h1hGb4ih1d2EZVw==',\n",
       " 'face_num': 1}"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "face_detect(API_key,API_secret,image_url)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "f513f571",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-22T11:08:57.554503Z",
     "start_time": "2022-03-22T11:08:57.360374Z"
    }
   },
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'base_url' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-4-c568d94369b6>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m     12\u001b[0m }\n\u001b[0;32m     13\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 14\u001b[1;33m \u001b[0mr\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mrequests\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpost\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mbase_url\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mparams\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mpayload\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m: name 'base_url' is not defined"
     ]
    }
   ],
   "source": [
    "face_detect_url = 'https://api-cn.faceplusplus.com/facepp/v3/faceset/create'\n",
    "\n",
    "# 2.准备api账户/通行证\n",
    "API_key =  'r651d0HgsEQqL55hCh1ZkOSmvz-HB8vF'\n",
    "API_secret = 'xSAcmge4iFneFOlloAm9k8lFP8W3iZP1'\n",
    "\n",
    "# 3.\n",
    "payload = {\n",
    "    'api_key':'r651d0HgsEQqL55hCh1ZkOSmvz-HB8vF',\n",
    "    'api_secret':'xSAcmge4iFneFOlloAm9k8lFP8W3iZP1',\n",
    "    'face_tokens':'2c135d5fc4dbda8c5830bc9c7fb1c9ca'\n",
    "}\n",
    "\n",
    "r = requests.post(base_url,params = payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5d7085f1",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 1.url\n",
    "base_url = 'https://api-cn.faceplusplus.com/facepp/v3/detect'\n",
    "API_key =  'r651d0HgsEQqL55hCh1ZkOSmvz-HB8vF'\n",
    "API_secret = 'xSAcmge4iFneFOlloAm9k8lFP8W3iZP1'\n",
    "\n",
    "payload = {\n",
    "    'api_key':'r651d0HgsEQqL55hCh1ZkOSmvz-HB8vF',\n",
    "    'api_secret':'xSAcmge4iFneFOlloAm9k8lFP8W3iZP1',\n",
    "     'image_url':'https://tse1-mm.cn.bing.net/th/id/OIP-C.HPWFQ7UDQh93EKcDmiUQ_wHaIR?w=176&h=197&c=7&r=0&o=5&dpr=2&pid=1.7'\n",
    "    \n",
    "}\n",
    "r = requests.post(base_url,params = payload)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
